<template>
  <div id="videolist">
    <div>
      <el-button @click="dotypes('新增')">新增</el-button>
    </div>
    <msg-list :tableData="tableData" :title="title" :checked="false" :pageshow="false" :sort="true" @upordown="upordown" :btntype="btntype" @getid="getid"></msg-list>
    <div class="layer" v-show="seecontent">
      <div class="mask" @click="seecontent = false"></div>
      <div class="content">
        <div class="title">
          {{addtitle}}
        </div>
        <span class="close" @click="seecontent = false"><i class="iconfont icon-untitled94"></i></span>
        <div class="shuru">
          <span>分类名</span>
          <el-input v-model="input" placeholder="请输入分类名"></el-input>
        </div>
        <div class="main-box" style="margin: 30px 0;">
          <span style="margin-left: 50px;"><el-button @click="addTags">确定</el-button></span>
          <span style="margin-left: 50px;"><el-button @click="seecontent = false">取消</el-button></span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import msgbox from '@/common/msgbox.js'
import MsgList from '../public/msgList'
import editor from '../../assets/editor/content'

export default {
  components: {
    MsgList,
    editor: editor},
  name: 'questions',
  data () {
    return {
      tableData: [],
      title: [
        {
          prop: 'id',
          label: 'id'
        },
        {
          prop: 'alias',
          label: '分类名'
        }
      ],
      btntype: ['修改', '删除'],
      delshow: false,
      seecontent: false,
      addtitle: '',
      input: '',
      getmsg: {}
    }
  },
  watch: {
    seecontent () {
      if (!this.seecontent) {
        this.input = ''
      }
    }
  },
  mounted () {
    this.search()
  },
  methods: {
    search () {
      let that = this
      this.$g.ajax({
        path: 'videocates/index',
        method: 'get',
        cbSuccess: function (data) {
          that.tableData = data.memo
        },
        cbError: function (data) {
          let msg = msgbox.get(data.msg)
          that.$message.error(msg)
        }
      })
    },
    dotypes (type) {
      this.seecontent = true
      this.addtitle = type
      if (type === '修改') {
        this.input = this.getmsg.alias
      } else if (type === '删除') {
        this.seecontent = false
        this.delhot()
      }
    },
    addTags () {
      let that = this
      if (this.addtitle === '新增') {
        this.$g.ajax({
          path: 'videocates/add',
          method: 'post',
          data: {
            alias: that.input
          },
          cbSuccess: function (data) {
            that.seecontent = false
            that.input = ''
            that.search()
          },
          cbError: function (data) {
            let msg = msgbox.get(data.msg)
            that.$message.error(msg)
          }
        })
      } else if (this.addtitle === '修改') {
        this.$g.ajax({
          path: 'videocates/edit/' + this.getmsg.id,
          method: 'post',
          data: {
            alias: that.input
          },
          cbSuccess: function (data) {
            that.seecontent = false
            that.input = ''
            that.search()
          },
          cbError: function (data) {
            let msg = msgbox.get(data.msg)
            that.$message.error(msg)
          }
        })
      }
    },
    move () {
      let that = this
      this.$g.ajax({
        path: 'videocates/move/' + this.getmsg.id + '/' + this.getmsg.type,
        method: 'post',
        data: {
          alias: that.input
        },
        cbSuccess: function (data) {
          that.seecontent = false
          that.input = ''
          that.search()
        },
        cbError: function (data) {
          let msg = msgbox.get(data.msg)
          that.$message.error(msg)
        }
      })
    },
    delhot () {
      let that = this
      this.$confirm('确定删除分类吗', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$g.ajax({
          path: 'videocates/delete/' + that.getmsg.id,
          method: 'get',
          cbSuccess: function (data) {
            that.search()
          },
          cbError: function (data) {
            let msg = msgbox.get(data.msg)
            that.$message.error(msg)
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    upordown (num) {
      console.log(num)
      this.getmsg = num
      this.move()
    },
    getid (vals) {
      console.log(vals)
      this.getmsg = vals.val
      this.dotypes(vals.btn)
    }
  }
}
</script>

<style lang="scss" scoped>
  .active{
    display: inline-block;
    -moz-transform:rotate(180deg);
    -webkit-transform:rotate(180deg);
    -o-transform:rotate(180deg);
    -ms-transform:rotate(180deg);
    transform:rotate(180deg);
  }
  #videolist {
    .main-box{
      margin-top: 20px;
      span{
        margin-right: 30px;
        font-size: 14px;
        font-weight: 700;
        color: #606266;
      }
      .el-input {
        width: 240px;
      }
    }
    .main-box {
      .el-radio__inner {
        background: red;
      }
      .el-radio__input.is-checked+.el-radio__label{
        color: #00a4a0!important;
      }
    }
    .layer {
      position: fixed;
      top: 0;
      left: 0;
      bottom: 0;
      right: 0;
      z-index: 999;
      .mask {
        background: rgba(153, 153, 153, 0.5);
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;
        z-index: 1;
      }
      .content {
        position: relative;
        width: 300px;
        background: #fff;
        margin: 10% auto;
        z-index: 2;
        padding: 30px;
        .close {
          position: absolute;
          right: 10px;
          top: 10px;
          cursor: pointer;
        }
        .title {
          text-align: center;
          font-size: 18px;
          font-weight: bold;
          margin-bottom: 20px;
        }
        .shuru {
          span {
            font-size: 14px;
            color: #666;
          }
          .el-input {
            width: 200px;
            margin-left: 20px;
          }
        }
        .el-date-editor.el-input, .el-date-editor.el-input__inner {
          position: relative;
          left: -4px;
        }
        .buttons {
          margin-top: 20px;
          text-align: center;
          button {
            margin: 0 20px;
          }
        }
      }
    }
  }
</style>
<style scoped>
  .el-button:focus, .el-button:hover{
    color: #00a4a0;
  }
  .el-button:active{
    border-color: #00a0a0;
  }
  .el-button{
    padding: 8px 14px;
  }
  .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner{
    background: #00a4a0;
    border-color: #00a4a0;
  }
  .transition-box {
    margin-bottom: 10px;
    width: 200px;
    height: 100px;
    border-radius: 4px;
    background-color: #409EFF;
    text-align: center;
    color: #fff;
    padding: 40px 20px;
    box-sizing: border-box;
    margin-right: 20px;
  }
</style>
